<template>
  <div>
      <!-------------------------------表格 ----------------------down ------------------->
      <el-card :body-style="{padding:'0px 8px'}" style="background-color: #f3f3f3">
        <!-------------------------------按钮 ----------------------down------------------->
        <div>
          <el-button icon="el-icon-edit" type="info" @click="add">新建</el-button>
          <el-input v-model="query.name" class="handle-input" placeholder="方案名称" />
          <el-button class="hand-btn" type="primary" icon="el-icon-search" @click="handleSearch">搜索</el-button>
       </div>
        <!-------------------------------按钮 ----------------------up ------------------->
        <el-card>
          <el-table
            ref="multipleTable"
            v-loading="loadingMTable"
            height="560"
            :cell-style="{'padding':'2px','font-size':'12px'}"
            :header-cell-style="{'padding':'0px','font-weight':'800'}"
            :data="page.content"
            border
            class="table"
            header-cell-class-name="table-header"
          >
            <el-table-column
              type="index"
              width="50"
            />
            <el-table-column prop="cdlcode" label="来料单号" />
            <el-table-column prop="projectName" label="方案名称" />
            <el-table-column prop="cdepname" label="部门名称" />
            <el-table-column prop="cinvname" label="产品名称" />
            <el-table-column prop="ccusname" label="客户名称" />
            <el-table-column prop="createBy" label="创建人" />
            <el-table-column prop="createTime" width="160" label="创建时间" />
            <el-table-column label="操作" width="180" align="center">
              <template slot-scope="scope">
                <el-button
                  type="text"
                  icon="el-icon-edit"
                  @click="handleEdit(scope.$index, scope.row)"
                >编辑</el-button>
                <el-button
                  type="text"
                  icon="el-icon-view"
                  style="color: #1ab394"
                  @click="handleView(scope.$index, scope.row)"
                >查看</el-button>
                <el-button
                  type="text"
                  icon="el-icon-delete"
                  class="red"
                  @click="handleDelete(scope.$index, scope.row)"
                >删除</el-button>
              </template>
            </el-table-column>
          </el-table>
          <div class="pagination">
            <el-pagination
              background
              layout="total,sizes, prev, pager, next"
              :page-sizes="[10,20, 30, 40, 50]"
              :current-page="query.pageIndex"
              :page-size="query.pageSize"
              :total="page.totalElements"
              @size-change="handleSizeChange"
              @current-change="handlePageChange"
            />
          </div>
        </el-card>
      </el-card>
      <!-------------------------------表格 ----------------------up ------------------->
  </div>
</template>
<script>
import { query } from '@/api/outcome'
import { delbyid } from '@/api/outcome'
export default {
  name: 'Quality',
  data() {
    return {
      loadingMTable: false,
      editVisible: false,
      query: {
        pageIndex: 1,
        pageSize: 20,
        name: ''
      },
      page: {}
    }
  },
  created() {
    this.getData()
  },
  methods: {
    // 获取 easy-mock 的模拟数据
    getData() {
      this.loadingMTable = true
      query(this.query).then(res => {
        this.loadingMTable = false
        this.page = res.data.page
      })
    },
    // 触发搜索按钮
    handleSearch() {
      this.$set(this.query, 'pageIndex', 1)
      this.getData()
    },
    // 删除操作
    handleDelete(index, row) {
      // 二次确认删除
      this.$confirm('确定要删除吗？', '提示', {
        type: 'warning'
      }).then(() => {
        delbyid(row.id).then(res => {
          this.$message.success('删除成功')
          this.getData()
        })
      })
        .catch(() => {
        })
    },
    // 编辑操作
    handleEdit(index, row) {
      this.$router.push({ path: 'outComeEdit', query: { id: row.id }})
    },
    handleView(index, row) {
      this.$router.push({ path: 'outComeView', query: { id: row.id }})
    },
    // 分页导航
    handlePageChange(val) {
      this.$set(this.query, 'pageIndex', val)
      this.getData()
    },
    // 分页大小改变
    handleSizeChange(val) {
      this.$set(this.query, 'pageSize', val)
      this.getData()
    },
    add() {
      this.$router.push({ path: 'outComeEdit' })
    }
  }
}
</script>

<style scoped>
  .handle-box {
    margin: 20px;
  }

  .handle-select {
    width: 120px;
  }

  .handle-input {
    margin: 10px;
    width: 300px;
    display: inline-block;
  }
  .table {
    width: 100%;
    font-size: 14px;
  }
  .red {
    color: #ff0000;
  }
  .hand-btn {
    margin: 5px;
  }
</style>
